package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.MemberEntity;
import com.my12306.train.model.entity.OrderEntity;
import com.my12306.train.service.MemberService;
import com.my12306.train.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户信息
 *
 * @author mifen¦
 * @email
 * @date 2020-08-24 20:58:07
 */
@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = memberService.queryMemberPage(pageVo);
        return ResponseData.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{memberId}")
    public ResponseData info(@PathVariable("memberId") Long memberId) {
        MemberEntity member = memberService.getById(memberId);

        return ResponseData.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResponseData save(@RequestBody MemberEntity member) {
        memberService.save(member);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResponseData update(@RequestBody MemberEntity member) {
        memberService.updateMemberById(member);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody List<Long> memberIds) {
        System.out.println(memberIds);
        memberService.deleteMemberBatchByIds(memberIds);
        return ResponseData.ok();
    }

}
